Back to Article
Data generating process 1
Download Notebook

Data generating process 1

In [1]:
%config InlineBackend.figure_format = "svg"
In [2]:
import networkx as nx
import matplotlib.pyplot as plt
In [8]:
fig, ax = plt.subplots(1, 1, figsize=(3, 1.5))

G = nx.DiGraph([
    ("$A$", "$Y$"), 
    # ("$X_0$", None),
    ("$X_A$", "$A$"),
    ("$X_{AY}$", "$A$"), ("$X_{AY}$", "$Y$"), 
    ("$X_Y$", "$Y$"),
])
G.add_node("$X_0$")
pos = {
    "$A$":[0,0], "$Y$":[5,0],
    "$X_0$":[1, 2], "$X_A$":[2,2],
    "$X_{AY}$":[3, 2], "$X_Y$":[4, 2],
}

nx.draw(G, pos=pos, ax=ax, with_labels=True, node_color="white")

In [9]:
fig, ax = plt.subplots(1, 1, figsize=(3, 1.5))

G = nx.DiGraph([
    ("$A$", "$Y$"), 
    ("$X_A$", "$A$"),
    ("$X_{AY}$", "$A$"), ("$X_{AY}$", "$Y$"), 
    ("$X_Y$", "$Y$"),
])
G.add_node("$X_0$")
pos = {
    "$A$":[0,0], "$Y$":[5,0],
    "$X_0$":[1, 2], "$X_A$":[2,2],
    "$X_{AY}$":[3, 2], "$X_Y$":[4, 2],
}

nx.draw(G, pos=pos, ax=ax, with_labels=True, node_color="white")
nx.draw_networkx_edges(
    G, pos=pos,
    edgelist=[
        ("$X_0$", "$A$"), ("$X_0$", "$Y$"),
        ("$X_A$", "$Y$"), ("$X_Y$", "$A$"),
    ],
    style="--",
    edge_color="0.25",
    ax=ax,
);

In [15]:
fig, axes = plt.subplots(1, 2, figsize=(10, 2.5))

G = nx.DiGraph([
    ("$A$", "$Y$"), 
    ("$X_A$", "$A$"),
    ("$X_{AY}$", "$A$"), ("$X_{AY}$", "$Y$"), 
    ("$X_Y$", "$Y$"),
])
G.add_node("$X_0$")
pos = {
    "$A$":[0,0], "$Y$":[5,0],
    "$X_0$":[1, 2], "$X_A$":[2,2],
    "$X_{AY}$":[3, 2], "$X_Y$":[4, 2],
}

nx.draw(G, pos=pos, ax=axes[1], with_labels=True, node_color="white", font_size=14)
nx.draw(G, pos=pos, ax=axes[0], with_labels=True, node_color="white", font_size=14)
nx.draw_networkx_edges(
    G, pos=pos,
    edgelist=[
        ("$X_0$", "$A$"), ("$X_0$", "$Y$"),
        ("$X_A$", "$Y$"), ("$X_Y$", "$A$"),
    ],
    style="--",
    edge_color="#9e3434",  # "#d12e2e"
    ax=axes[0],
)
axes[0].set_title("Assumed confounding structure", fontsize=14, pad=12)
axes[1].set_title("Actual confounding structure", fontsize=14, pad=12);
fig.subplots_adjust(wspace=0);
# fig.tight_layout();
Figure 1: Confounding structure underlying the simulation example. Right is the true confounding structure where \(X_0\) is not associated with neither the exposure \(A\) nor the outcome \(Y\), \(X_A\) only influence the exposure, \(X_Y\) only influences the outcome, and \(X_{AY}\) is the only true confounder influencing both \(A\) and \(Y\). Left is the assumed confounding structure where all variables assumed to be confounders influencing both the treatment and the outcome. Wrongly specified edges are depicted red and dashed.